import java.util.Scanner;


public class StackTraceTest {

  public static void main(String[] args) {
    Scanner scanner = new Scanner(System.in);
    System.out.print("Enter n: ");
    int n = scanner.nextInt();
    factorial(n);
  }

  public static int factorial(int n) {
    System.out.println("factorial(" + n + "):");

    Throwable t = new Throwable();
    StackTraceElement[] frames = t.getStackTrace();
    for (StackTraceElement f : frames)
      System.out.println(f);

    int r = n <= 1 ? 1 : n * factorial(n - 1);
    System.out.println("return " + r);
    return r;
  }

}
